package com.hq.fxh.No6UerSpace.Fragment;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.hq.fxh.CustomerView.CircleImageView;
import com.hq.fxh.No6UerSpace.Adapter.Ladapter_JianLi_Education;
import com.hq.fxh.No6UerSpace.Adapter.Ladapter_JianLi_Work;
import com.hq.fxh.R;
import com.hq.fxh.Utils.LogUtils;
import com.hq.fxh.Utils.Tool;

import static com.hq.fxh.Utils.Tool.setListViewHeightBasedOnChildren;


/**
 * /**
 *
 * @author 薛
 * @ClassName
 * @Description :
 * @Created 2017/9/19
 * @Email xlwenhao1858@sina.com
 */


public class Fragment_JianLi extends Fragment {

    protected View rootView;
    protected TextView mode1TvJianLiZhangTai;
    protected CircleImageView mode1ImageJianLiHeadPic;
    protected TextView mode1TvJIanLiName;
    protected ImageView mode1ImageJianLiSex;
    protected TextView mode1TvJIanLiAge;
    protected TextView mode1TvJIanLiAddress;
    protected TextView mode1TvJIanLiWorkTime;
    protected TextView mode1TvJIanLiPhone;
    protected TextView mode1TvJIanLiEmail;
    protected TextView mode2TvJianLiZhiWei;
    protected TextView mode2TvJianLiGongZhi;
    protected TextView mode2TvJianLiWorkStyle;
    protected TextView mode2TvJianLiWorkAddress;
    protected TextView mode2TvJianLiFuJia;
    protected ListView listSpaceWork;
    protected ListView listSpaceEducation;
    private Ladapter_JianLi_Education educationAdapter;
    private Ladapter_JianLi_Work workAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_space_jianli, null);

        initView(rootView);
        initData();

        return rootView;
    }

    private void initData() {
        educationAdapter = new Ladapter_JianLi_Education();
        listSpaceEducation.setAdapter(educationAdapter);

        workAdapter = new Ladapter_JianLi_Work();
        listSpaceWork.setAdapter(workAdapter);
        workAdapter.notifyDataSetChanged();
      Tool. setListViewHeightBasedOnChildren(listSpaceEducation);
        Tool.  setListViewHeightBasedOnChildren(listSpaceWork);

    }


    public static Fragment_JianLi newInstance() {

        Bundle args = new Bundle();

        Fragment_JianLi fragment = new Fragment_JianLi();
        fragment.setArguments(args);
        return fragment;
    }

    private void initView(View rootView) {
        mode1TvJianLiZhangTai = (TextView) rootView.findViewById(R.id.mode1_tv_JianLi_ZhangTai);
        mode1ImageJianLiHeadPic = (CircleImageView) rootView.findViewById(R.id.mode1_image_JianLi_HeadPic);
        mode1TvJIanLiName = (TextView) rootView.findViewById(R.id.mode1_tv_JIanLi_Name);
        mode1ImageJianLiSex = (ImageView) rootView.findViewById(R.id.mode1_image_JianLi_Sex);
        mode1TvJIanLiAge = (TextView) rootView.findViewById(R.id.mode1_tv_JIanLi_Age);
        mode1TvJIanLiAddress = (TextView) rootView.findViewById(R.id.mode1_tv_JIanLi_Address);
        mode1TvJIanLiWorkTime = (TextView) rootView.findViewById(R.id.mode1_tv_JIanLi_WorkTime);
        mode1TvJIanLiPhone = (TextView) rootView.findViewById(R.id.mode1_tv_JIanLi_Phone);
        mode1TvJIanLiEmail = (TextView) rootView.findViewById(R.id.mode1_tv_JIanLi_Email);
        mode2TvJianLiZhiWei = (TextView) rootView.findViewById(R.id.mode2_tv_JianLi_ZhiWei);
        mode2TvJianLiGongZhi = (TextView) rootView.findViewById(R.id.mode2_tv_JianLi_GongZhi);
        mode2TvJianLiWorkStyle = (TextView) rootView.findViewById(R.id.mode2_tv_JianLi_WorkStyle);
        mode2TvJianLiWorkAddress = (TextView) rootView.findViewById(R.id.mode2_tv_JianLi_WorkAddress);
        mode2TvJianLiFuJia = (TextView) rootView.findViewById(R.id.mode2_tv_JianLi_FuJia);
        listSpaceWork = (ListView) rootView.findViewById(R.id.list_Space_Work);
        listSpaceEducation = (ListView) rootView.findViewById(R.id.list_Space_Education);
    }

    int totalHeight = 0;

    public void setListViewHeightBasedOnChildren2(ListView listView) {
        ListAdapter listAdapter = listView.getAdapter();
        if (listAdapter == null) {
            return;
        }
        totalHeight = 0;

        for (int i = 0; i < 1; i++) {

            View mView = listAdapter.getView(i, null, listView);
            getHeight2(mView);

        }


    }

    public void getHeight2(final View imageView) {
        ViewTreeObserver vto = imageView.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                imageView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                imageView.getHeight();
                imageView.getWidth();

                LogUtils.e("im==="+imageView.getHeight());
            }
        });
    }




    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            LogUtils.e("handle==" + msg.what);
        }
    };

}
